import 'package:erp/data/api/process_api.dart';
import 'package:erp/data/model/page.dart';
import 'package:erp/data/model/process.dart';
import 'package:erp/routes/app_pages.dart';
import 'package:erp/widgets/page_list/page_list_control.dart';
import 'package:get/get.dart';

class FlowViewController extends PageListControl<Process> {
  // control overlay
  var showOverlay = false.obs;

  // query param
  int pageIndex = 1;
  Rx<dynamic> status = Rx<dynamic>(null);
  String keyWord = "";

  get queryParam => {
        "typeCode": "SALE_PROJECT",
        "keyWord": keyWord,
        "processStatus": status.value,
      };

  @override
  void onInit() {
    super.onInit();
  }

  @override
  void dispose() {
    super.dispose();
  }

  void search(String text) {
    this.keyWord = text;
    this.showOverlay.value = false;
    easyRefreshController.callRefresh();
  }

  void detail(Process item) async {
    var data = await ProcessApi.getDetail(item.processNo);
    Get.toNamed(Routes.SALE_PROJECT_PROCESS_DETAIL, arguments: {'data': data});
  }

  @override
  Future<PageData<Process>> loadPageData({required int pageIndex}) async {
    var data = await ProcessApi.queryFlowSee(queryParam, pageIndex);
    var list = data["records"].map<Process>((m) => Process.fromJson(m)).toList();
    return PageData(records: list, size: data["size"]);
  }
}
